import App from './App'

/* WebSocket close 代码修正补丁：将非法 1006 归一为 1000（正常关闭） */
;(function patchSocketClose() {
  const apis = [];
  try {
    if (typeof uni !== 'undefined' && uni && typeof uni.closeSocket === 'function') {
      apis.push({ obj: uni, key: 'closeSocket' });
    }
  } catch (e) {}
  try {
    if (typeof wx !== 'undefined' && wx && typeof wx.closeSocket === 'function') {
      apis.push({ obj: wx, key: 'closeSocket' });
    }
  } catch (e) {}
  apis.forEach(({ obj, key }) => {
    const original = obj[key];
    if (typeof original !== 'function') return;
    obj[key] = function(arg) {
      try {
        if (arg && typeof arg === 'object' && 'code' in arg && arg.code === 1006) {
          const patched = { ...arg, code: 1000 };
          return original.call(this, patched);
        }
      } catch (e) {
        // 忽略补丁内部错误，回退到原有调用
      }
      return original.apply(this, arguments);
    };
  });
})();
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif